package com.itheima.utils;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

/**
 * ClassName: CodeUtils
 * Description:
 * Date: 2023/03/11 AM 12:35:52
 * <p>
 * project: springboot
 * package: com.itheima.utils
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
@Component
public class CodeUtils {

    private static final String[] PATCH = {"00000", "0000", "000", "00", "0", ""};

    public String generator(String tele) {
        int hash = tele.hashCode();
        int encryption = 20206666;
        int result = hash ^ encryption;
        long nowTime = System.currentTimeMillis();
        result ^= nowTime;
        long code = result % 1000000;
        code = code < 0 ? -code : code;
        String codeStr = code + "";
        int len = codeStr.length();
        return PATCH[len - 1] + codeStr;
    }

    @Cacheable(value = "smsCode", key = "#tele")
    public String get(String tele) {
        return null;
    }

    public static void main(String[] args) {
        System.out.println(new CodeUtils().generator("18866668888"));
    }
}
